package Exercise108;

import java.util.Random;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {

//        String A="ABCDE";
//        String B="BCDEA";
//        Judge(A,B);

//        Scanner sc = new Scanner(System.in);
//        System.out.println("输入字符串：");
//        String input = sc.next();
//        String result=ranDisrupt(input);
//        System.out.println(result);

//        Verify();

//        String s1="171368";
//        String s2="12";
//        String s3=Multiply(s1,s2);
//        System.out.println(s3);

        int count=Reserve1("i think i can be a Tencent employer");
        System.out.println("最后一个单词的长度位"+count);

    }



    //给一个字符串 空格隔开每一个单词 返回最后一个单词的长度
    public static int Reserve1(String s1) {
        StringBuilder sb = new StringBuilder(s1);
        String tmp = sb.reverse().toString();
        char c = tmp.charAt(0);
        int i = 0;
        int count = 0;
        while (tmp.charAt(i) != ' ') {
            count++;
            i++;
        }
        return count;
    }


    //给定两个字符串 返回乘积也用字符串的形式
    public static String Multiply(String s1, String s2) {

        int mul1 = 0;
        int mul2 = 0;
        for (int i = 0; i < s1.length(); i++) {
            int c = (int) (s1.charAt(i) - 48);
            mul1 = mul1 * 10 + c;
        }
        for (int i = 0; i < s2.length(); i++) {
            int c = (int) (s2.charAt(i) - 48);
            mul2 = mul2 * 10 + c;
        }
        int result = mul1 * mul2;
        StringBuilder sb = new StringBuilder();
        while (result != 0) {
            char c = (char) (result % 10 + 48);
            sb.append(c);
            result /= 10;
        }
        return sb.reverse().toString();
    }


    //验证码2.0
    public static void Verify() {
        char[] arr = new char[5];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            int s = r.nextInt(2);
            char a = (char) (r.nextInt(26) + 65);
            char b = (char) (r.nextInt(26) + 97);
            if (s == 0) {
                arr[i] = a;
            } else {
                arr[i] = b;
            }
        }
        int a = r.nextInt(5);
        char b = (char) (r.nextInt(10) + 48);
        arr[a] = b;
        String oug = new String(arr);
        System.out.println(oug);
    }


    //随机打乱内容
    public static String ranDisrupt(String arr) {
        char[] str = new char[arr.length()];
        for (int i = 0; i < arr.length(); i++) {
            str[i] = arr.charAt(i);
        }
        Random r = new Random();
        for (int i = 0; i < arr.length() / 2; i++) {
            int a = r.nextInt(arr.length());
            char tmp = str[a];
            str[a] = str[i];
            str[i] = tmp;
        }
        arr = new String(str);
        return arr;
    }

    //给定两个字符串 右旋判断是否相等
    public static void Judge(String A, String B) {
        int i;
        for (i = 0; i < A.length(); i++) {
            String nea = A.substring(i);
            StringBuilder sb = new StringBuilder(nea);
            for (int j = 0; j < i; j++) {
                char c = A.charAt(j);
                sb.append(c);
            }
            if (sb.toString().equals(B)) {
                System.out.println("可以");
                i--;
                break;
            }
        }

        if (i == A.length()) {
            System.out.println("不可以");
        }
    }


}
